﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WFAExamAuto.SysSettings
{
    public partial class frmBackUp : Form
    {
        public FrmMain fmain = new FrmMain();
        string mypath;
        string myOldpath;
        public frmBackUp()
        {
            InitializeComponent();
            mypath = Application.StartupPath.ToString();
            mypath = mypath.Substring(0, mypath.LastIndexOf("\\"));
            mypath = mypath.Substring(0, mypath.LastIndexOf("\\")) + "\\ExamAutoBackup\\";
            myOldpath = mypath;
            if(!System.IO.Directory.Exists(mypath))
            {
                System.IO.Directory.CreateDirectory(mypath);
            }
            tbPath.Text = mypath + System.DateTime.Today.ToString("yyyyMMdd");
        }

        private void btnOpenFile_Click(object sender, EventArgs e)
        {
            
            folderBrowserDialog1.ShowDialog();
            mypath = folderBrowserDialog1.SelectedPath + "\\ExamAutoBackup\\";
            if (!System.IO.Directory.Exists(mypath))
            {
                System.IO.Directory.CreateDirectory(mypath);
            }
            tbPath.Text = mypath+System.DateTime.Today.ToString("yyyyMMdd");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(!System.IO.File.Exists(myOldpath+"backupPath.txt"))
            {
                System.IO.File.CreateText(myOldpath + "backupPath.txt");
            }
            System.IO.File.OpenWrite(myOldpath + "backupPath.txt");
            FileStream fs = new FileStream(myOldpath + "backupPath.txt", FileMode.Open);
            StreamWriter sw = new StreamWriter(fs, Encoding.Unicode);
            sw.Write(tbPath.Text);
            this.Close();
        }
    }
}
